package cn.shopifymall.spring.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author 孤风雪影
 * @Email gitee.com/efairy520
 * @Date 2024/12/31 0:06
 * @Version 1.0
 */
@Component
@Aspect
public class LogAspect {

    @Pointcut("execution(public int cn.shopifymall.spring.util.MathCalculator.*(..))")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint) {
        System.out.println("除法开始:方法名称:" + joinPoint.getSignature().getName());
    }

    @After("pointCut()")
    public void logEnd() {
        System.out.println("除法结束");
    }

    @AfterReturning(value = "pointCut()", returning = "result")
    public void logReturn(Object result) {
        System.out.println("除法返回,结果:" + result);
    }

    @AfterThrowing(value = "pointCut()", throwing = "e")
    public void logException(JoinPoint joinPoint, Exception e) {
        System.out.println("除法异常" + e.getMessage());
    }
}
